#pragma once

class System_HistoryGraph : public Console_Subscriber
{
	struct LineRecord
	{
		bool	mbEnabled;
		float	mfPos;
		COLOR	mColor;
		LineRecord(bool Enable, float Position, COLOR Color)
			: mbEnabled(Enable), mfPos(Position), mColor(Color){}
	};

	struct GraphRecrod
	{
		COLOR			mColor;
		std::vector <hgeVertex> mVertices;
		int				mPos;
		GraphRecrod(int Size, COLOR Color, Vector & Position);
		~GraphRecrod();

		void AddPoint(const float & Point);
	};
	
	std::deque <GraphRecrod>	mGraph_Records;
	std::deque <LineRecord>		mLine_Records;

	hgeVertex		mLine[2];

	int				mLineHighLightMin,	mLineHighLightMax;
	float			mfHighLightMin,		mfHighLightMax;
	Vector			mPosition;
	hgeRect			mWindowView;
	unsigned int	mFlags;

	bool			mbActive;
public:
	System_HistoryGraph();
	virtual ~System_HistoryGraph();

	inline void		Activate(const bool & OnOff) { mbActive = OnOff; }
	inline bool		IsActive()			const { return mbActive; }

	inline int		LineHighLightMin()	const { return mLineHighLightMin; }
	inline int		LineHighLightMax()	const { return mLineHighLightMax; }
	inline Vector	Position()			const { return mPosition; }			
	inline void		Position(const Vector & Position) { mPosition = Position; }

	inline bool		EnableScaling()		const { return (mFlags & 1) != 0; }
	void			EnableScaling(const bool & OnOff);

	inline bool		ShowHighLightsLimit()	const { return (mFlags & 2) != 0; }
	void			ShowHighLightsLimit(const bool & OnOff);
	void			SetHighLights(const float & Min, const float & Max);
	void			SetDimension(const int & Width, const int & Height);
	

	int				AddGraph(COLOR Color);
	int				AddLine(const float & Pos, COLOR Color);
	inline void		SetLine(const int & id, const float & Pos) { mLine_Records[id].mfPos = Pos + mPosition.y; }
	inline void		AddPoint(const float & Pos, int id = 0) { mGraph_Records[id].AddPoint(Pos + mPosition.y); }

	void Parse(const std :: string & Input);
	void Render();
};

extern SmartPtr <System_HistoryGraph> g_pSystem_HistoryGraph;